package paypal

import (
	"os"

	"github.com/Peakchen/xgameCommon/akLog"
	"github.com/plutov/paypal"
)

type akPaypal struct {
	cli *paypal.Client
}

var akpp *akPaypal

func NewAkPaypal() {
	akpp = &akPaypal{}
	var err error
	akpp.cli, err = paypal.NewClient(StrClientID, StrSecretID, paypal.APIBaseSandBox)
	if err != nil {
		akLog.Error("paypal create client fail, %v", err)
		os.Exit(1)
		return
	}
	token, err := akpp.cli.GetAccessToken()
	if err != nil {
		akLog.Error("get token fail, %v", err)
		return
	}
	akLog.FmtPrintln("token: ", *token)
}

func DefaultPayPal() *akPaypal {
	return akpp
}

func (this *akPaypal) GetClient() *paypal.Client {
	return this.cli
}
